package darlingbastard.stacks;

import darlingbastard.stacks.TowerSupport;

import javax.servlet.jsp.tagext.BodyTag;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;

/**
 * Created by bishope
 * Date: Mar 13, 2006
 */
public class WithTag implements BodyTag {

    private PageContext pageContext;
    private Tag parent;
    private TowerSupport towerSupport;

    private String var;

    public void setBodyContent(BodyContent bodyContent) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    public void doInitBody() throws JspException {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    public int doAfterBody() throws JspException {
        return 0;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public void setPageContext(PageContext pageContext) {
        this.pageContext = pageContext;
        this.towerSupport = TowerSupport.get(pageContext);
    }

    public void setParent(Tag tag) {
        this.parent = tag;
    }

    public Tag getParent() {
        return this.parent;
    }

    public int doStartTag() throws JspException {
        towerSupport.select(var);
        return 0;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public int doEndTag() throws JspException {
        towerSupport.unselect();
        return 0;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public void release() {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    public void setVar(String var) {
        this.var = var;
    }

    static public String absolutePath(String path) {
        if (!path.startsWith(".")) return path;
        if (currentPath() == null) return path.substring(1);
        return currentPath() + path;
    }

    private static String currentPath() {
        return null;  //To change body of created methods use File | Settings | File Templates.
    }

}
